package com.GlobalPaint.app.Adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.GlobalPaint.app.R;
import com.GlobalPaint.app.bean.MyFriendBean;
import com.GlobalPaint.app.ui.App;
import com.GlobalPaint.app.ui.Home.friend.GuanzhuFragment;
import com.GlobalPaint.app.ui.Mine.Personal.PersonalZhanshi;
import com.GlobalPaint.app.utils.Constants;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2018/1/18 0018.
 */

public class MyGuanzhuAdapter extends XRecyclerView.Adapter<MyGuanzhuAdapter.ViewHoler>{
    private List<MyFriendBean.DataBean> bean;
    private GuanzhuFragment guanzhuFragment;


    public MyGuanzhuAdapter(List<MyFriendBean.DataBean> list, GuanzhuFragment guanzhuFragment) {
        this.guanzhuFragment=guanzhuFragment;
        bean=list;
    }

    @Override
    public MyGuanzhuAdapter.ViewHoler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.frament_guanzhu_item, parent, false);
        MyGuanzhuAdapter.ViewHoler holder = new MyGuanzhuAdapter.ViewHoler(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyGuanzhuAdapter.ViewHoler holder, final int position) {
        String Phone=bean.get(position).getJid()==
                null?"":bean.get(position).getJid();
        if (Phone.length() > 4) {
            String phone1 = (Phone.substring(0, 3));
            String phone2 = Phone.substring(Phone.length() - 3, Phone.length());
            holder.tv_name.setText(phone1 + "***" + phone2);
        }
        String Nick=bean.get(position).getNick()==
                null?bean.get(position).getJid():bean.get(position).getNick();
        String Url= bean.get(position).getAvatar()== null?"wu":
                bean.get(position).getAvatar();
        if(Url.equals("wu")){
            Picasso.with(App.context).load(R.drawable.touxiang).into(holder.imge);
        }else {
            Picasso.with(App.context).load(Constants.JASON_SERVICE_URL_TOUXIANG+Url)
                    .placeholder(R.drawable.touxiang).into(holder.imge);
        }
        holder.tv_nick.setText(Nick);
       /* holder.mview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(view.getContext(), PersonalZhanshi.class);
                intent.putExtra("Nick",bean.get(position).getNick());
                intent.putExtra("Name",bean.get(position).getUserName());
                intent.putExtra("Nick",bean.get(position).getNick());
                intent.putExtra("Nick",bean.get(position).getNick());
                intent.putExtra("Nick",bean.get(position).getNick());
                intent.putExtra("Nick",bean.get(position).getNick());
                intent.putExtra("Nick",bean.get(position).getNick());
                intent.putExtra("Nick",bean.get(position).getNick());
                view.getContext().startActivity(intent);
            }
        });*/
        holder.imge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(view.getContext(), PersonalZhanshi.class);
                intent.putExtra("userid",bean.get(position).getUserId());
                view.getContext().startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return bean.size();
    }

    public class ViewHoler extends RecyclerView.ViewHolder {

        private final TextView tv_name;
        private final TextView tv_nick;
        private final ImageView imge;

        View mview;

        public ViewHoler(View itemView) {
            super(itemView);
            mview = itemView;
            tv_name = (TextView)itemView.findViewById(R.id.tv_name);
            tv_nick = (TextView)itemView.findViewById(R.id.tv_nick);
            imge = (ImageView)itemView. findViewById(R.id.imge);
        }
    }
}
